﻿using System.Collections.Generic;
using LitJson;
using UnityEngine;

namespace abilities
{
    public class AbilityDatabase
    {
        static Dictionary<string, Ability> _abilities = new ();
        public static Ability GetAbility( string id)
        {
            if(_abilities.ContainsKey(id))
                return  _abilities[id];
            return null;
        }

        public static void Load()
        {
            _abilities.Clear();
            TextAsset[] tas = Resources.LoadAll<TextAsset>("ability");
            foreach (var ta in tas)
            {
                Ability ability = new Ability();
                JsonData jd = JsonMapper.ToObject(ta.text);
                if(ability.FromJson(jd))
                    _abilities.Add(ability.id,ability);
            }
        }
    }
}